package com.skydonkey.pojo.vo;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Result<T> {

    private static final Logger log = LoggerFactory.getLogger(Result.class);
    private int code;   //一个状态码
    private String msg; //附带消息
    private T data;    //数据

    public Result(){}

    public Result(ResultEnum resultEnum){
        this.msg = resultEnum.getMsg();
        this.code = resultEnum.getCode();
    }


    public Result(ResultEnum resultEnum,T data){
        this.msg = resultEnum.getMsg();
        this.code = resultEnum.getCode();
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public void setCodeAndMsg(ResultEnum code) {
        this.code = code.getCode();
        this.msg = code.getMsg();
    }

    public static Logger getLog() {
        return log;
    }

    public int getCode() {
        return code;
    }

    public Result<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static <V> Result<V> success(V data){
        return new Result<>(ResultEnum.SUCCESS, data);
    }
    public static Result<Object> success(){
        return new Result<>(ResultEnum.SUCCESS);
    }


    public static <V> Result<V> failed(V data){
        return new Result<>(ResultEnum.FAILED, data);
    }

    public static Result<Object> failed(){
        return new Result<>(ResultEnum.FAILED);
    }

}